package gxdlxy.vote;

class Student{
    int id, advise;
    Student(int id, int advise) {
        this.id = id; this.advise = advise;
    }
    void vote(VotingBox votingBox){
        votingBox.voted(this.id, this.advise);
    }
}
class VotingBox{
    boolean[] is_vote = new boolean[10];
    int[] advises = new int[10];
    // 接收选票
    void voted(int id, int advice) {
        if(this.is_vote[id]) {
            // 重复投票
            System.out.println("请勿重复投票");
        } else {
            // 若没有，则存储投票意见，并把该学生标记为已投票
            this.advises[id] = advice;
            this.is_vote[id] = true;
            System.out.println("感谢您的投票");
        }
    }
    void stat(){
        int sum = 0;
        for(int i=0;i<10;i++)
            if(this.is_vote[i])
                sum++;
        System.out.println("当前有"+sum+"个学生投票");
        int[] stu_vote = new int[4];
        for(int i=0;i<10;i++)
            stu_vote[this.advises[i] - 1]++;
        System.out.println("陈万宝获得" + stu_vote[0]+"票");
        System.out.println(stu_vote[1]);
        System.out.println(stu_vote[2]);
        System.out.println(stu_vote[3]);
    }
}
